@extends('master/master_index')

@section('title')
    <title>个人中心</title>
@endsection

@section('css')
    <link rel="stylesheet" type="text/css" href="{{asset('home/css/Topic_UserCenter.css')}}">
    <style>

        html, body {
            margin: 0;
            padding: 0;
        }

        .wrap-dialog {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            font-size: 16px;
            text-align: center;
            background-color: rgba(0, 0, 0, .4);
            z-index: 999;
        }

        .dialog {
            position: relative;
            margin: 15% auto;
            width: 300px;
            background-color: #FFFFFF;

        }

        .dialog .dialog-header {
            height: 20px;
            padding: 10px;
            background-color: lightskyblue;
        }

        .dialog .dialog-body {
            height: 30px;
            padding: 20px;
        }

        .dialog .dialog-footer {
            padding: 12px;
            background-color: whitesmoke;
        }

        .btn {
            width: 70px;
            padding: 2px;
        }

        .hide {
            display: none;
        }

        .ml50 {
            margin-left: 50px;
        }
    </style>
@endsection

@section('content')
    <div class="con_content">
        <div class="big_table">
                <div class="small_table">
                    <div class="table_top">
                        <div class="img_header"><img src="{{asset($user->profile['avatar'])}}"></div>
                        <ul class="table_t_l">
                            <li class="username">{{$user['username']}}</li>
                            @if($user->profile->gender==1)
                                <li class="li_gender"><img class="gender_img gender3" src="{{asset('home/img/man.png')}}"></li>
                            @elseif($user->profile->gender==0)
                                <li class="li_gender"><img class="gender_img_woman gender2" src="{{asset('home/img/woman.png')}}"></li>
                            @endif
                            <li class="vip">第 <span>{{$user['id']}}</span> 名成员</li>
                            <li>注册于 <span>{{$user['created_at']->diffForHumans()}}</span></li>
                            <li>活跃于 <span>{{$user['updated_at']->diffForHumans()}}</span></li>
                        </ul>

                    </div>
                    <div class="table_content">
                        <ul>
                            <li class="Ta_li_follower">
                                <p>{{count($user->another)}}</p>
                                <span>关注者</span>
                            </li>
                            <li class="Ta_li_topic">
                                <p>{{count($user->topic)}}</p>
                                <span>文章</span>
                            </li>
                            <li class="Ta_li_reply">
                                <p>{{count($user->reply)}}</p>
                                <span>评论</span>
                            </li>
                        </ul>
                    </div>
                    <div class="table_foot">
                        @if(Session::has('userModel'))
                            @if($user->id==Session::get('userModel')->id)
                                <a class="user_center_a profile_update_a" href="{{url('myUserCenter')}}">个人中心</a>
                            @else
                                @if($followed==0)
                                    <a href="{{url('follow')}}/another={{$user->id}}" class="yellow y2"><i class="Hui-iconfont">&#xe717;&nbsp;</i>关注Ta</a>
                                @else
                                    <a href="{{url('followDown')}}/another={{$user->id}}" class="yellow y2 followDown"><i class="Hui-iconfont">&#xe69d;&nbsp;</i>已关注</a>
                                @endif
                            @endif
                        @else
                            <a onclick="login_follow()" class="yellow y2"><i class="Hui-iconfont">&#xe717;&nbsp;</i>关注Ta</a>
                        @endif
                    </div>
                </div>
        </div>
        <div class="con_left_wrap">
            <div class="con_left">
                <div >
                    @if(!empty($user->profile->signature))
                        <p class="signature">{{$user->profile->signature}}</p>
                        @else
                        <p class="signature">这个人很懒,什么都没留下</p>
                    @endif
                </div>
            </div>
            <div class="con_left">
                <div class="le_top">最近文章</div>
                    @if(count($user->topic)>0)
                        <div class="le_foot">
                            <ul>
                                @foreach($user->topic as $p)
                                    <li>
                                        <a href="{{url('topic')}}/topics={{$p['id']}}" class="a1">{{$p->title}}</a>
                                        <span class="s1">
                                            @foreach($p->tags as $g)
                                                <span class="e">{{$g->tag_name}}</span>
                                            @endforeach
                                            <p>{{count($p->replies)}}回复</p>
                                            <p>{{$user['created_at']->diffForHumans()}}</p>
                                        </span><br/>
                                        <a style="opacity: 0" class="update_a" href="#"><i class="Hui-iconfont" style="color:#a2d3e5;">&#xe72a;</i></a>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    @else
                        <div id="none">暂无评论！</div>
                    @endif
            </div>
            <div class="con_left">
                <div class="le_top">最近评论</div>
                    @if(count($user->reply)>0)
                        <div class="le_foot2">
                            <ul>
                                @foreach($user->reply as $p)
                                    <li class="reply_li">
                                        <a href="{{url('topic')}}/topics={{$p->topic['id']}}" class=" a2">{{$p->topic->title}}</a><span> at {{$p['created_at']->diffForHumans()}}</span><br/>
                                        <p class="reply_i">@if(!empty($p->answer_id))<a href="{{url('userCenter')}}/user={{$p->answer_id}}" class="blue_reply reply_s">@ {{$p->answer->username}}:</a></span>@endif{{$p->content}}</p>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    @else
                        <div id="none">暂无评论！</div>
                    @endif
            </div>
        </div>
        <div class="big_table_next">
            <input class="hide_input_user_id" type="hidden" value="{{$user->id}}">
            <ul>
                <li class="Ta Ta_topic"><i class="Hui-iconfont i_ta">&#xe652;</i> Ta 发布的文章</li>
                <li class="Ta Ta_reply"><i class="Hui-iconfont i_ta">&#xe622;</i> Ta 发表的评论</li>
                <li class="Ta Ta_follow"><i class="Hui-iconfont i_ta">&#xe650;</i> Ta 关注的用户</li>
                <li class="Ta Ta_vote"><i class="Hui-iconfont i_ta">&#xe66d;</i> Ta 点赞的文章</li>
            </ul>
        </div>
        <div class="wrap-dialog hide">
            <div class="dialog">
                <div class="dialog-header">
                    <span class="dialog-title">登录确认</span>
                </div>
                <div class="dialog-body">
                    <span class="dialog-message">此功能需登录</span>
                </div>
                <div class="dialog-footer">
                    <a href="{{url('login')}}" ><input type="button" class="btn" value="前去登录"></a>
                    <input type="button" class="btn ml50" id="cancel" value="取消"/>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script type="application/javascript">
        var followerUrl='{{url('Ta_follower')}}';
        var topicUrl='{{url('Ta_topic')}}';
        var replyUrl='{{url('Ta_reply')}}';
        var followUrl='{{url('Ta_follow')}}';
        var voteUrl='{{url('Ta_vote')}}';

        function login_follow() {
            $('.wrap-dialog').fadeIn();
            $('#cancel').click(function () {
                $('.wrap-dialog').slideUp();
            });
        }

        (function (window, $) {
            var messages = {
                init: function () {
                    $('.s3').click(this.delete_topic.bind(this));
                },
                delete_topic: function (event) {
                    var topic_id = $(event.target).children('input').val();
                    $.ajax({
                        type: 'POST',
                        url:'{{url('delete_topic')}}',
                        data: {topic_id:topic_id},
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                        },
                        success: function () {
                            $(event.target).parents('li').slideUp(300,function () {
                                $(this).remove();
                            });
                        },
                        error: function () {
                            alert('Ajax error!')
                        }
                    });
                }

            };
            messages.init();
        })(window, jQuery);
    </script>
@endsection
